package com.yq.design.singleton.doubleCheck;

/**
 * @ClassName Singleton
 * @Description 双重检查，声明私有volatile 属性，私有构造器，公有方法，加sychronized,如果为空，同步该类，继续判断，如果为空，new
 * @Author yaoqiang
 * @Date 2021/3/8 18:28
 * @Version 1.0
 */
public class Singleton {
    private static  volatile  Singleton instance;

    private Singleton() {
    }
    //提供一个公有的方法，
    public static synchronized Singleton getInstance(){
        if (instance==null){
            synchronized (Singleton.class){
                if(instance==null){
                    instance= new Singleton();
                }
            }
        }
        return instance;
    }

}
